<template>
  <div class="wdinfobox">
    <div class="winfo">
      <img :src="wthImg" alt="" />
      <span class="wetext">多云 16°C </span>
    </div>

    <div class="dateinfo">
      <span class="datetext">{{ timeInfo.date }}</span>
      <span class="wktext">{{ timeInfo.weekday }}</span>
    </div>
    <div class="time">
      {{ timeInfo.time }}
    </div>
  </div>
</template>
<script lang="ts" setup>
import { getTimeInfo } from '@/utils';
import { ref, reactive, onBeforeUnmount } from 'vue';

//@ts-ignore
const wthIconModules: any = import.meta.glob('/src/assets/img/weather/*.png', {
  eager: true,
});
let wthPath = ref(`/src/assets/img/weather/W1.png`);
//@ts-igore
let wthImg = ref(wthIconModules[wthPath.value].default || '');

let timeInfo = reactive({
  time: '',
  date: '',
  weekday: '',
});

let timeInfoTimer = setInterval(() => {
  let { time, date, weekday } = getTimeInfo();
  timeInfo.time = time;
  timeInfo.date = date;
  timeInfo.weekday = weekday;
}, 1000);

onBeforeUnmount(() => {
  if (timeInfoTimer) clearInterval(timeInfoTimer);
});
</script>
<style lang="scss" scoped>
.wdinfobox {
  overflow: hidden;
  height: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .winfo {
    margin-right: 20px;

    img {
      height: 24px;
      width: 30px;
      float: left;
    }

    .wetext {
      font-size: 16px;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      color: #ffffff;
      line-height: 30px;
      margin-left: 6px;
      //opacity: 0.8;
      float: left;
      background: angular-gradient(180deg,
          #ffffff 0%,
          rgba(0, 0, 0, 0.38) 47%,
          #ffffff 50%,
          rgba(0, 0, 0, 0.38) 100%);
    }
  }

  .time {
    font-size: 22px;
    font-family: D-DIN-Bold;
    color: #ffffff;
    line-height: 24px;
    text-shadow: 0px 0px 3px rgba(7, 104, 203, 0.92);
  }

  .dateinfo {
    font-size: 14px;
    font-family: PingFangSC-Regular;
    font-weight: 400;
    color: #ffffff;
    line-height: 12px;
    margin-right: 20px;

    .wktext {
      margin-left: 10px;
    }
  }
}
</style>
